package com.mida.dms.knw.controller;

import com.mida.dms.knw.entity.vo.KnwIndividualRelationVo;
import com.mida.dms.knw.entity.vo.KnwIndividualVo;
import com.mida.dms.knw.entity.vo.MapperPage;
import com.mida.dms.knw.service.KnwIndividualRelationService;
import com.mida.dms.knw.vo.KnwIndividualRelationPageVo;
import com.mida.dms.knw.vo.PageResultVo;
import com.mida.tool.common.result.ActionResult;
import com.mida.tool.common.result.ListResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <h1>实例关系</h1>
 * <p>
 *
 * </p>
 *
 * @author jian.li on 2021/7/15 15:12
 */
@RestController
@RequestMapping("/knwIndividualRelation")
@Api(tags = "实例关系维护")
@CrossOrigin
@Slf4j
public class KnwIndividualRelationController {

    @Autowired
    KnwIndividualRelationService knwIndividualRelationService;

    @ApiOperation(value = "新增单条实例关系",notes = "新增单条实例关系")
    @PostMapping(value = "/addRelation",consumes = {"application/json;charset=UTF-8"},produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ActionResult addSingle(@RequestBody KnwIndividualRelationVo relation){
        return knwIndividualRelationService.addSingle(relation);
    }

    @ApiOperation(value = "编辑实例关系",notes = "编辑实例关系")
    @PostMapping(value = "/updateRelation",consumes = {"application/json;charset=UTF-8"},produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ActionResult updateSingle(@RequestBody KnwIndividualRelationVo relation){
        return knwIndividualRelationService.updateSingle(relation);
    }

    @ApiOperation(value = "删除实例关系",notes = "删除实例关系")
    @GetMapping(value = "/delete",produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ActionResult delete(@RequestParam("soid") Long individualRelationSoid){
        return knwIndividualRelationService.delete(individualRelationSoid);
    }

    @ApiOperation(value = "批量新增实例关系", notes = "批量新增实例关系")
    @PostMapping(value = "/addRelationList", consumes = {"application/json;charset=UTF-8"}, produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ActionResult addList(@RequestBody List<KnwIndividualRelationVo> relationList) {
        return knwIndividualRelationService.addList(relationList);
    }

    @ApiOperation(value = "分页查询实例关系", notes = "分页查询实例关系")
    @PostMapping(value = "/findPage", consumes = {"application/json;charset=UTF-8"}, produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ListResult<PageResultVo<KnwIndividualRelationVo>> findPage(@RequestBody KnwIndividualRelationPageVo vo) {
        return knwIndividualRelationService.findPage(vo);
    }

    @ApiOperation(value = "根据实例关系soid查询实例关系", notes = "根据实例关系soid查询实例关系")
    @GetMapping(value = "/findSingle", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ListResult<KnwIndividualRelationVo> findSingle(@RequestParam("soid") Long individualRelationSoid){
        return knwIndividualRelationService.findSingle(individualRelationSoid);
    }

    @ApiOperation(value = "启用(停用)实例关系", notes = "启用(停用)实例关系")
    @GetMapping(value = "/enable", produces = {"application/json;charset=UTF-8"})
    public ActionResult enable(@RequestParam("soid") Long soid) {
        return knwIndividualRelationService.enable(soid);
    }

    @ApiOperation(value = "源实例目标实例下拉", notes = "源实例目标实例下拉")
    @PostMapping(value = "/findSourceAndTarget", consumes = {"application/json;charset=UTF-8"}, produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ListResult<List<KnwIndividualVo>> findSourceAndTarget(@RequestBody MapperPage page) {
        return knwIndividualRelationService.findSourceAndTarget(page);
    }

    @ApiOperation(value = "实例关系下拉", notes = "实例关系下拉")
    @GetMapping(value = "/findRelation", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public ListResult<Object> findRelation(@RequestParam("searchData") String searchData) {
        return knwIndividualRelationService.findRelation(searchData);
    }
}

